import static sun.plugin2.os.windows.OSVERSIONINFOA.size;

public class MyLibkedList {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;//标记双向链表的头部
    public ListNode tail;//标记双向链表的尾部

    public void addFirst(int data){
      ListNode node=new ListNode(data);
      if(this.head==null){
          this.head=node;
          this.tail=node;
      }else {
          node.next = this.head;
          this.head.prev = node;
          node = this.head;
      }
    }
    //任意位置插入,第一个数据节点为0号下标
    public void addIndex(int index,int data)
            throws   IndexWrongException{
//1、判断Index位置的合法性
      if(index<0||index> size()){
     throw new IndexWrongException("插入位置错误");
}
//2、判断特殊位置，头插 和 尾插
      if(index==0){

        }
      if(index==size()){

        }

//3、找到index位置节点的地址
        ListNode cur = findIndexListNode( index);

    }

    private ListNode findIndexListNode(int index) {
        ListNode cur = this.head;
        int count = 0;
        while (index!=0) {
            cur=cur.next;
            index--;
        }
        return cur;
    }
    //置空
    public void clear(){
         ListNode curNext=this.head;
         ListNode cur=this.head;
         while(cur!=null){
             curNext=cur.next;
             cur.next=null;
             cur.prev=null;
             cur=cur.next;
         }
         head=null;
         tail=null;
    }
}
